Passed
Pull Request — master (#45)
by
unknown
06:19
created

popover.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap popover.js v4.5.3 (https://getbootstrap.com/)
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./tooltip.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './tooltip.js'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Popover = factory(global.jQuery, global.Tooltip));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
}(this, (function ($, Tooltip) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Tooltip__default = /*#__PURE__*/_interopDefaultLegacy(Tooltip);
16
17
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
19
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
21
  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
22
23
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 23 as a function. While this will work, it can be very confusing.
Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
24
  /**
25
   * ------------------------------------------------------------------------
26
   * Constants
27
   * ------------------------------------------------------------------------
28
   */
29
30
  var NAME = 'popover';
31
  var VERSION = '4.5.3';
32
  var DATA_KEY = 'bs.popover';
33
  var EVENT_KEY = "." + DATA_KEY;
34
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
35
  var CLASS_PREFIX = 'bs-popover';
36
  var BSCLS_PREFIX_REGEX = new RegExp("(^|\\s)" + CLASS_PREFIX + "\\S+", 'g');
37
38
  var Default = _extends({}, Tooltip__default['default'].Default, {
39
    placement: 'right',
40
    trigger: 'click',
41
    content: '',
42
    template: '<div class="popover" role="tooltip">' + '<div class="arrow"></div>' + '<h3 class="popover-header"></h3>' + '<div class="popover-body"></div></div>'
43
  });
44
45
  var DefaultType = _extends({}, Tooltip__default['default'].DefaultType, {
46
    content: '(string|element|function)'
47
  });
48
49
  var CLASS_NAME_FADE = 'fade';
50
  var CLASS_NAME_SHOW = 'show';
51
  var SELECTOR_TITLE = '.popover-header';
52
  var SELECTOR_CONTENT = '.popover-body';
53
  var Event = {
54
    HIDE: "hide" + EVENT_KEY,
55
    HIDDEN: "hidden" + EVENT_KEY,
56
    SHOW: "show" + EVENT_KEY,
57
    SHOWN: "shown" + EVENT_KEY,
58
    INSERTED: "inserted" + EVENT_KEY,
59
    CLICK: "click" + EVENT_KEY,
60
    FOCUSIN: "focusin" + EVENT_KEY,
61
    FOCUSOUT: "focusout" + EVENT_KEY,
62
    MOUSEENTER: "mouseenter" + EVENT_KEY,
63
    MOUSELEAVE: "mouseleave" + EVENT_KEY
64
  };
65
  /**
66
   * ------------------------------------------------------------------------
67
   * Class Definition
68
   * ------------------------------------------------------------------------
69
   */
70
71
  var Popover = /*#__PURE__*/function (_Tooltip) {
72
    _inheritsLoose(Popover, _Tooltip);
73
74
    function Popover() {
75
      return _Tooltip.apply(this, arguments) || this;
76
    }
77
78
    var _proto = Popover.prototype;
79
80
    // Overrides
81
    _proto.isWithContent = function isWithContent() {
82
      return this.getTitle() || this._getContent();
83
    };
84
85
    _proto.addAttachmentClass = function addAttachmentClass(attachment) {
86
      $__default['default'](this.getTipElement()).addClass(CLASS_PREFIX + "-" + attachment);
87
    };
88
89
    _proto.getTipElement = function getTipElement() {
90
      this.tip = this.tip || $__default['default'](this.config.template)[0];
91
      return this.tip;
92
    };
93
94
    _proto.setContent = function setContent() {
95
      var $tip = $__default['default'](this.getTipElement()); // We use append for html objects to maintain js events
96
97
      this.setElementContent($tip.find(SELECTOR_TITLE), this.getTitle());
98
99
      var content = this._getContent();
100
101
      if (typeof content === 'function') {
102
        content = content.call(this.element);
103
      }
104
105
      this.setElementContent($tip.find(SELECTOR_CONTENT), content);
106
      $tip.removeClass(CLASS_NAME_FADE + " " + CLASS_NAME_SHOW);
107
    } // Private
108
    ;
109
110
    _proto._getContent = function _getContent() {
111
      return this.element.getAttribute('data-content') || this.config.content;
112
    };
113
114
    _proto._cleanTipClass = function _cleanTipClass() {
115
      var $tip = $__default['default'](this.getTipElement());
116
      var tabClass = $tip.attr('class').match(BSCLS_PREFIX_REGEX);
117
118
      if (tabClass !== null && tabClass.length > 0) {
119
        $tip.removeClass(tabClass.join(''));
120
      }
121
    } // Static
122
    ;
123
124
    Popover._jQueryInterface = function _jQueryInterface(config) {
125
      return this.each(function () {
126
        var data = $__default['default'](this).data(DATA_KEY);
127
128
        var _config = typeof config === 'object' ? config : null;
129
130
        if (!data && /dispose|hide/.test(config)) {
131
          return;
132
        }
133
134
        if (!data) {
135
          data = new Popover(this, _config);
136
          $__default['default'](this).data(DATA_KEY, data);
137
        }
138
139
        if (typeof config === 'string') {
140
          if (typeof data[config] === 'undefined') {
141
            throw new TypeError("No method named \"" + config + "\"");
142
          }
143
144
          data[config]();
145
        }
146
      });
147
    };
148
149
    _createClass(Popover, null, [{
150
      key: "VERSION",
151
      // Getters
152
      get: function get() {
153
        return VERSION;
154
      }
155
    }, {
156
      key: "Default",
157
      get: function get() {
158
        return Default;
159
      }
160
    }, {
161
      key: "NAME",
162
      get: function get() {
163
        return NAME;
164
      }
165
    }, {
166
      key: "DATA_KEY",
167
      get: function get() {
168
        return DATA_KEY;
169
      }
170
    }, {
171
      key: "Event",
172
      get: function get() {
173
        return Event;
174
      }
175
    }, {
176
      key: "EVENT_KEY",
177
      get: function get() {
178
        return EVENT_KEY;
179
      }
180
    }, {
181
      key: "DefaultType",
182
      get: function get() {
183
        return DefaultType;
184
      }
185
    }]);
186
187
    return Popover;
188
  }(Tooltip__default['default']);
189
  /**
190
   * ------------------------------------------------------------------------
191
   * jQuery
192
   * ------------------------------------------------------------------------
193
   */
194
195
196
  $__default['default'].fn[NAME] = Popover._jQueryInterface;
197
  $__default['default'].fn[NAME].Constructor = Popover;
198
199
  $__default['default'].fn[NAME].noConflict = function () {
200
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
201
    return Popover._jQueryInterface;
202
  };
203
204
  return Popover;
205
206
})));
207
//# sourceMappingURL=popover.js.map
208